package com.ballcat.spring.cloud.learning.controller;

import com.ballcat.spring.cloud.learning.common.CommonResult;
import com.ballcat.spring.cloud.learning.entity.Payment;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @author pengshun
 * @date 2022-04-04 18:23
 * @description
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "/order")
public class OrderController {

    public static final String PAYMENT_URL = "http://cloud-payment-service";

    private final RestTemplate restTemplate;

    @PostMapping(value = "save")
    public CommonResult<Integer> save(@RequestBody Payment payment) {
        CommonResult result = restTemplate.postForObject(PAYMENT_URL + "/payment/save", payment, CommonResult.class);
        return result;
    }

    @GetMapping(value = "/getById")
    public CommonResult<Payment> getById(@RequestParam Integer id) {
        CommonResult result = restTemplate.getForObject(PAYMENT_URL + "/payment/getById?id=" + id, CommonResult.class);
        return result;
    }
}
